package demo.practice.leetcode_eveyday;

public class P1190 {

    public static void main(String[] args) {
        P1190 p1190= new P1190();
        String s = p1190.reverseParentheses("a(bcdefghijkl(mno)p)q");
        System.out.println(s);


    }

    public String reverseParentheses(String s) {
        //双指针
        int i=0;
        int j=s.length()-1;

        //Character[] chars= new Character[];
        int a=-0;
        int b=0;

        boolean positive=true;
        StringBuffer sbfront=  new StringBuffer();
        StringBuffer sbafter=  new StringBuffer();


        StringBuffer cur= sbfront;
        while (i<=j){
            char c= positive?s.charAt(i++) :s.charAt(j--);
            if(c!='('&& c!= ')'){
                if(cur==sbfront)
                    cur.append(c);
                else
                    cur.insert(0,c);
            }else{
                positive=!positive;
                if(c=='(')
                {
                    if(cur== sbfront){
                        cur= sbafter;
                    }else{
                        cur= sbfront;
                    }
                }
            }
        }
        return sbfront.toString()+sbafter.toString();
    }
}
